export const Base = {
	data () {
            return {
            	operateModal:false,
                list: [],
                filter:{
                	total:0,
	                limit:10,
	                page:1,
	                name:''
                },
                ids:[],
                id:0,
                moudel:'users'    
            }	
        },
        methods: {
            show (index) {
                this.$Modal.info({
                    title: 'User Info',
                    content: `Name：${this.data6[index].name}<br>Age：${this.data6[index].age}<br>Address：${this.data6[index].address}`
                })
            },
            remove (params) {
                this.$Modal.confirm({
                    title: '确认删除数据',
                    content: '<p>你确认删除该条数据吗</p>',
                    onOk: () => {
                        this.axios({
                        	url:`http://localhost:3000/${this.moudel}/data/${params.row._id}`,
                        	method:'delete'
                        }).then(res=>{
                        	this.$Message.info('删除数据成功');
                        	this.getListData();
                        })
                    },
                    onCancel: () => {
                        this.$Message.info('取消删除');
                    }
                });
            },
            getListData(){
            	this.axios({
	        			url:`http://localhost:3000/${this.moudel}/list`,
	        			method:'post',
	        			data:this.filter
	        		}).then(res=>{
                        console.log(res);
	        			this.list=res.data.rows;
	        			this.filter.total = res.data.total;
	        			this.filter.limit = res.data.limit;
	        		})
            },
            onPageChange(page){
	            	this.filter.page=page;
	            	this.getListData();
	        },
	        onPageSizeChange(limit){
	        	this.filter.limit=limit;
	        	this.getListData();
	        },
	        onSelectionChange(selection){
	        	var ids=[];
	        	for(let i=0;i<selection.length;i++){
	        		ids.push(selection[i]._id)
	        	}
	        	this.ids=ids;
	        	console.log(ids);

	        },
	        removes(){
	        	this.$Modal.confirm({
                    title: '确认删除数据',
                    content: '<p>你确认删除该条数据吗</p>',
                    onOk: () => {
                        this.axios({
                        	url:`http://localhost:3000/${this.moudel}/removes`,
                        	method:'post',
                        	data:{
                        		ids:this.ids.toString()
                        	}
                        }).then(res=>{
                        	this.$Message.info('删除数据成功');
                        	this.getListData();
                        })
                    },
                    onCancel: () => {
                        this.$Message.info('取消删除');
                    }
                });
	        },
	        search(){
	        	console.log(this.filter)
	        	this.onPageChange(1);
	        },
	        addData(){
	        	this.operateModal=true;
	        	this.formValidate={};
           		this.$refs.formValidate.resetFields();
	        },
	        editData(params){
	        	this.axios({
	        		url:`http://localhost:3000/${this.moudel}/data/${params.row._id}`,
	        		method:'get'
	        	}).then(res=>{
	        		this.formValidate=res.data;
	        		this.operateModal=true;
	        		this.id=params.row._id;
	        	})
	        },
	        handleSubmit (name) {
                this.$refs[name].validate((valid) => {
                    if (valid) {
                    	if(this.id !== 0){
                    		this.axios({
                    			url:`http://localhost:3000/${this.moudel}/data/${this.id}`,
                    			method:'put',
                    			data:this.formValidate
                    		}).then(res=>{
                    			this.operateModal=false;
		                       	 this.$Message.success('数据操作成功!');
		                       	 this.getListData();
		                       	 this.id=0;
                    		})
                    	}else{
                    		this.axios({
	                        	url:`http://localhost:3000/${this.moudel}/data`,
	                        	method:'post',
	                        	data:this.formValidate
	                        }).then(res=>{
		                         this.operateModal=false;
		                       	 this.$Message.success('数据操作成功!');
		                       	 this.getListData();
	                        })
                    	}          
                    } else {
                        this.$Message.error('Fail!');
                    }
                })
            },
            handleReset (name) {
                this.$refs[name].resetFields();
            }
       	 },
        mounted(){
        		this.getListData();
        }
}